import hashlib


class HashUtils:
    """
        哈希算法模块
    """

    @staticmethod
    def md5_encode(data):
        """
            md5加密
        """
        return hashlib.md5(data.encode('utf-8')).hexdigest()

    @staticmethod
    def check_md5(data, md5):
        """
            检查md5是否一致
        """
        return HashUtils.md5_encode(data) == md5

    @staticmethod
    def sha256_encode(data):
        """
            sha256加密
        """
        return hashlib.sha256(data.encode('utf-8')).hexdigest()

    @staticmethod
    def check_sha256(data, sha256):
        """
            检查sha256是否一致
        """
        return HashUtils.sha256_encode(data) == sha256

    @staticmethod
    def base64_encode(data):
        """
            base64加密
        """
        return data.encode('utf-8').decode('utf-8')

    @staticmethod
    def base64_decode(data):
        """
            base64解密
        """
        return data.encode('utf-8')




